33
has-a
part-of
Has-a relationship
This relationship is just the inverse version of the part-of relationship. Therefore we can easily add this relationship to the part-of illustration by adding arrows in the
other direction.
Circle
Logo
Triangle
part-of
has-a
You sometimes need to be able to build objects by combining them out of others. You already know this from procedural programming, where you have the
structure or record construct to put data of various types together.
Let's come back to our drawing program. You already have created several classes for the available figures. Now you decide that you want to have a special figure
which represents your own logo which consists of a circle and a triangle. (Let's assume, that you already have defined a class Triangle.) Thus, your logo consists of
two parts or the circle and triangle are part-of your logo.